# 3.实现一个 atoi 函数，使其能将字符串转换成整数
def my_atoi(s: str) -> int:
    s = s.strip()
    num = 0
    sign = -1 if s[0] == '-' else 1
    for char in s:
        if not char.isdigit():
            continue
        num = num*10+eval(char)
    num *= sign
    return num




if __name__ == '__main__':
    print(my_atoi("42"))  # 输出: 42
    print(my_atoi("   -42"))  # 输出: -42
    print(my_atoi("4193 abcd case"))  # 输出: 4193  此题不允许使用int()
